package com.xyp.mesadmin.md.type.controller;

import com.xyp.mesadmin.md.type.VO.SelectTypeVO;
import com.xyp.mesadmin.md.type.service.MdItemTypeService;
import com.xyp.mescommon.common.R;
import com.xyp.mesadmin.md.type.VO.MdItemTypeVO;
import com.xyp.mescommon.entity.md.MdItemType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * --- 加油，努力 ---
 *
 * @Author XYP
 * @Date 2024/9/26
 * @Solgne 从想做到能做
 * @Desc
 */
@RestController
@RequestMapping("/md/type")
@Api(tags ="物料类型管理API")
public class MdItemTypeController {
    @Autowired
    private MdItemTypeService mdItemTypeService;
    //查询
    @ApiOperation("查询所有类型")
    @GetMapping("/list")
    public R findAll (){
        List<MdItemTypeVO> itemTypeVOS = mdItemTypeService.findAllItemType();
        return R.ok(itemTypeVOS);
    }
    //根据id查询
    @GetMapping("/itemTypeInfo")
    public R findById (Integer id) {
        MdItemType mdItemType = mdItemTypeService.findById(id);
        return R.ok(mdItemType);
    }
    //删除
    @GetMapping("/delete")
    public R deleteById (Integer id){
        mdItemTypeService.delete(id);
        return R.ok();
    }
    //添加
    @PostMapping("/add")
    public R addItemType (@RequestBody MdItemType mdItemType){
        mdItemTypeService.add(mdItemType);
        return R.ok();
    }
    //修改
    @PostMapping("/update")
    public R updateType (@RequestBody MdItemType mdItemType){
        System.out.println(mdItemType);
        mdItemTypeService.update(mdItemType);
        return R.ok();
    }

    @GetMapping("/TreeVO")
    public R listTypeTreeVO () {
        List<SelectTypeVO> selectTypeVOS = mdItemTypeService.selectTypeVO();
        return R.ok(selectTypeVOS);
    }


}
